#include <mutex>
#include <iostream>
template <typename T>
class Singleton {
public:
    Singleton(const Singleton&) = delete;
    Singleton& operator=(const Singleton&) = delete;

    static T& instance() {
        static T instance;
        return instance;
    }

protected:
    Singleton() {}
    ~Singleton() {}
};

// 使用示例
class MySingletonClass : public Singleton<MySingletonClass> {
    friend class Singleton<MySingletonClass>; // 允许Singleton访问私有构造函数
public:
    void operation() {
        std::cout << "Operation called." << std::endl;
    }

protected:
    MySingletonClass() {}
};

int main() {
    MySingletonClass& singletonInstance = MySingletonClass::instance();
    singletonInstance.operation();
}